<template>
  <j-modal :title="title" :width="800" :visible="visible" :maskClosable="false" :fullscreen="true" @close="close">
    <template slot="footer">
      <a-button key="back" style="padding-left: 8px; padding-right: 8px" @click="close(false)"> 关闭 </a-button>
      <template v-if="permissionInit && active == completeTab && subActiveTab == completesubTab">
        <a-button
          :disabled="status == '9' || status == '2' || status == '3'"
          v-permission="['50010']"
          type="primary"
          @click="showConfirm"
          style="padding-left: 8px; padding-right: 8px"
        >
          完成归档阶段
        </a-button>
        <a-button
          :disabled="status !== '2'"
          v-permission="['50020']"
          @click="setApproveReason('9')"
          style="padding-left: 8px; padding-right: 8px"
        >
          同意
        </a-button>
        <a-button
          :disabled="status !== '2'"
          v-permission="['50020']"
          type="danger"
          @click="setApproveReason('1')"
          style="padding-left: 8px; padding-right: 8px"
        >
          拒绝
        </a-button>
        <a-button
          :disabled="status === '9'"
          type="danger"
          key="save"
          style="padding-left: 8px; padding-right: 8px"
          @click="setReason()"
        >
          撤销到报告阶段
        </a-button>
      </template>
    </template>
    <div style="margin: 0 auto" :class="{ isCheck: isCheck }">
      <!-- <a-steps :current="current" @change="onChange">
          <a-step description="已完成" title="准备阶段" />
          <a-step description="已完成" title="实施阶段" />
          <a-step description="已完成" title="报告阶段" />
          <a-step description="已完成" title="整改阶段" />
          <a-step :description="status === '9' ? '已完成' : '进行中'" title="归档阶段" />
        </a-steps> -->
      <sjSteps @change="onChange">
        <sjStepsItem
          title="准备阶段"
          :active="current == 0"
          :index="0"
          sub_title="已完成"
          bgimage="mid_row"
          icon_img="icon1"
        />
        <sjStepsItem
          title="实施阶段"
          :active="current == 1"
          :index="1"
          sub_title="已完成"
          bgimage="mid_row"
          icon_img="icon2"
        />
        <sjStepsItem
          title="报告阶段"
          :active="current == 2"
          :index="2"
          sub_title="已完成"
          bgimage="mid_row"
          icon_img="icon3"
        />
        <sjStepsItem
          title="归档阶段"
          :active="current == 3"
          :index="3"
          :sub_title="status === '9' ? '已完成' : '进行中'"
          bgimage="mid_row"
          icon_img="icon5"
          :img_size="false"
        />
<!--        <sjStepsItem
          title="整改阶段"
          :active="current == 4"
          :index="4"
          sub_title="未执行"
          bgimage="mid_row"
          icon_img="icon4"
        />-->
      </sjSteps>
      <div class="detail">
        <div class="name">
          {{ model.name }}<span>{{ model.stageText }}</span>
        </div>
        <div class="list">
          <div>
            项目编号：<span>{{ model.number }}</span>
          </div>
          <div>
            项目类别：<span>{{ model.type_dictText }}</span>
          </div>
          <div>
            主审计单位：<span>{{ $store.getters.departInfo.departName }}</span>
          </div>
          <div>
            被审计单位：<span>{{ model.bsjdwName }}</span>
          </div>
          <div>
            审计期间：<span>{{ model.startDate }} ~ {{ model.endDate }}</span>
          </div>
        </div>
      </div>

      <component :is="active" :model="model" @subActiveTab="getSubActiveTab"> </component>
    </div>
    <SelectApprove ref="approver" :id="model.id" @submitData="handleSubmit"></SelectApprove>
    <SetReason ref="setReason" @approveReason="approveData"></SetReason>
    <SetReason ref="chSetReason" @approveReason="returnPro"></SetReason>
  </j-modal>
</template>
<script>
import { WORK_AUTH } from '@/store/mutation-types'
import { getAction } from '@/api/manage'
import viewTypeId from '../commView/public/typeId'
import SetReason from '../commView/public/SetReason'
import SelectApprove from '../commView/public/SelectApprover'
import { butStatus } from '../butStatus'
import zbContentView from './zbContentView'
import ssContentView from './ssContentView'
import bgContentView from './bgContentView'
import zgContentView from './zgContentView'
import gdContentView from './gdContentView'
import sjSteps from '@/views/sj/components/sjSteps/sjSteps'
import sjStepsItem from '@/views/sj/components/sjSteps/sjStepsItem'

export default {
  name: 'contentView',
  components: {
    SetReason,
    SelectApprove,
    zbContentView,
    ssContentView,
    bgContentView,
    zgContentView,
    gdContentView,
    sjSteps,
    sjStepsItem,
  },
  mixins: [butStatus],
  data() {
    return {
      current: 3,
      active: 'gdContentView',
      completeTab: 'gdContentView',
      subActiveTab:null,
      completesubTab:'gdxxqr',
      permissionInit: false,
      viewTypeId: viewTypeId,
      typeId: viewTypeId['审计归档'],
      activeList: {
        0: 'zbContentView',
        1: 'ssContentView',
        2: 'bgContentView',
        3: 'gdContentView',
        4: 'zgContentView',
      },
      disableSubmit: false,
      title: '',
      visible: false,
      isCheck: false,
      url: {
        returnPro: '/sjxmzygl/sjWorkUsers/recallLastStage',
        permission: '/sys/permission/getButtonByUser',
        submit: '/sjxmzygl/sjWorkUsers/submitAudit',
        approve: '/sjxmzygl/sjWorkUsers/zyApplyCommit',
        butStatus: '/sjxmzygl/sjWorkUsers/queryStageInfo',
      },
      model: {},
      isShow: false,
    }
  },
  methods: {
    onChange(current) {
      this.current = current
      this.active = this.activeList[current]
      this.subActiveTab = null
    },

    getSubActiveTab(obj){
      this.subActiveTab = obj
    },
    
    getWorkAuth() {
      this.isShow = false
      this.permissionInit = false
      getAction(this.url.permission, { proId: this.model.id }).then((res) => {
        if (res.success) {
          this.isShow = true
          let workAuthData = res.result.workButtonAuth
          sessionStorage.setItem(WORK_AUTH, JSON.stringify(workAuthData))
          this.permissionInit = true
        }
      })
    },
    edit(record) {
      this.subActiveTab = null
      this.model = Object.assign({}, record)
      this.getWorkAuth()
      this.getStstus()
      this.visible = true
    },
    close() {
      this.visible = false
    },
    setReason() {
      this.$refs.chSetReason.setApproveReason = true
    },
    //撤回
    returnPro(reason) {
      getAction(this.url.returnPro, {
        proId: this.model.id,
        typeId: this.typeId,
        stage: '03010',
        remark: reason,
      }).then((res) => {
        if (res.success) {
          this.$message.success(res.message)
          this.$refs.chSetReason.setApproveReason = false
          this.$emit('ok')
          this.close()
        } else {
          this.$message.error(res.message)
        }
      })
    },
  },
}
</script>

<style lang='less' scoped>
@import '../../css/checkAndEdit.less';

.card {
  border: 0;
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
}
</style>
